package com.qf.staff.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageInfo;
import com.qf.common.base.result.RespResult;
import com.qf.staff.common.qo.EmpQo;
import com.qf.staff.common.vo.EmpVo;
import com.qf.staff.service.EmpService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "员工管理Api")
@RestController
@RequestMapping("/emp")
public class EmpController {
    @Resource
    EmpService empService;

    @ApiOperation("查询所有员工信息")
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "page", value = "页码"),
                    @ApiImplicitParam(name = "size", value = "条数"),
                    @ApiImplicitParam(name = "empName", value = "员工名")
            })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @GetMapping("/list")
    public RespResult<IPage<EmpVo>> list(@RequestParam(defaultValue = "1") int page,
                                         @RequestParam(defaultValue = "10") int size,
                                         String empName) {
        return RespResult.success(empService.list(page, size, empName));
    }

    @ApiOperation("根据id修改status为0是删除员工信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "empId", value = "员工id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/remove")
    public RespResult<Integer> remove(EmpQo empQo) {
        return RespResult.success(empService.delete(empQo));
    }

    @ApiOperation("根据ID修改员工信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "empId", value = "员工id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PutMapping("/modify")
    public RespResult<Integer> modify(EmpQo empQo) {
        return RespResult.success(empService.modify(empQo));
    }

    @ApiOperation("根据id修改status为0是批量删除部门信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "deptId", value = "部门id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/delete/all/{status}")
    public int deleteAll(@RequestBody List<Integer> ids, @PathVariable("status") int status) {
        return empService.deleteAll(ids, status);
    }

    @ApiOperation("添加员工信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "empName", value = "员工姓名"),
            @ApiImplicitParam(name = "sex", value = "员工性别 0是女 1是男"),
            @ApiImplicitParam(name = "deptId", value = "员工所属部门"),
            @ApiImplicitParam(name = "status", value = "员工状态"),
            @ApiImplicitParam(name = "file", value = "头像")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PostMapping("/add")
    public RespResult<Integer> add(EmpQo empQo, MultipartFile file) {
        return RespResult.success(empService.add(empQo, file));
    }


    @ApiOperation("查询所有员工信息及部门信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码"), @ApiImplicitParam(name = "size", value = "条数")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @GetMapping("/listEmp")
    public RespResult<PageInfo<EmpVo>> listEmp(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        return RespResult.success(empService.listEmp(page, size));
    }
}
